﻿using System;
using System.Diagnostics;
using System.Web;
using CY_MVC.HttpHandlers;
using MyControllers.Models;
using System.Collections.Generic;

namespace MyControllers
{
    public class @default : PageController
    {
        public @default()
        {
            CacheSeconds = 0;
            //TemplatePath = @"\Test\Test"; 不需要页面的后缀名了
        }

        protected override void Page_Load()
        {
            ViewData["TemplatePath"] = CY_MVC.StaticConfig.TemplatePath;
            ViewData["ExtendPage"] = CY_MVC.StaticConfig.RootPath + CY_MVC.StaticConfig.TemplatePath + "_main.html";


            Stopwatch sw = new Stopwatch();
            sw.Start();

            Title = "标题:" + Request.RawUrl;
            Keywords = "我是Keywords" + DateTime.Now.ToLongTimeString();
            Description = "我是Description 好人" + DateTime.Now.ToLongTimeString();



            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                RegisterScript("alert('Request.QueryStrin：" + Request.QueryString["id"] + "');");
                Response.Cookies.Add(new HttpCookie("id", Request.QueryString["id"]));
            }
            if (Request.Cookies.Get("id") != null)
            {
                RegisterScript("alert('Request.Cookies：" + Request.Cookies.Get("id") + "');");
            }
            sw.Stop();

            ViewData["processtime"] = sw.Elapsed.TotalMilliseconds.ToString();
        }

        public string CheckLogin(string username, string password)
        {
            return "帐号：" + username + "|密码：" + password + "|是否登录：" + (Session["islogon"] != null ? Session["islogon"].ToString() : "空值") + "|时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void SetLogin(bool res)
        {
            Session["islogon"] = res;
        }

        public News GetNews(int id, bool hot)
        {
            News temp = new News();
            temp.Title = "新闻" + id;
            temp.ID = id;
            temp.AddDate = DateTime.Now.AddDays(5);
            temp.Hot = hot;
            temp.Key = Guid.NewGuid();
            return temp;
        }

        public string ShowUser(Users usermodel)
        {
            return "用户：" + usermodel.name.ToString() + "|注册日期：" + usermodel.regdate.ToString("yyyy-MM-dd HH:mm:ss");
        }
        public string ShowUsers(List<Users> usermodels)
        {
            return "用户：" + usermodels[1].name.ToString() + "|注册日期：" + usermodels[1].regdate.ToString("yyyy-MM-dd HH:mm:ss");
        }


    }
    public enum names
    {
        曹操, 吕布
    }
    public class Users
    {
        private names m_name;

        public names name
        {
            get { return m_name; }
            set { m_name = value; }
        }
        private bool m_sex;

        public bool sex
        {
            get { return m_sex; }
            set { m_sex = value; }
        }
        private DateTime m_regdate;

        public DateTime regdate
        {
            get { return m_regdate; }
            set { m_regdate = value; }
        }
        private double m_money;

        public double money
        {
            get { return m_money; }
            set { m_money = value; }
        }
    }
}